home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / fhopen.lha / test.c < prev   
Encoding:
C/C++ Source or Header  |  1994-12-08  |  1.6 KB  |  65 lines

  1. #include <dos/dos.h>
  2. #include <clib/dos_protos.h>
  3. #include <stdio.h>
  4.  
  5. #include <string.h>
  6. extern FILE *   fhopen(BPTR, char *);
  7. extern int      fhclose(FILE *fp);
  8.  
  9. #define NAME    "T:test"
  10. #define MSG     "hello world"
  11.  
  12. main()
  13. {
  14.     BPTR fh;
  15.     FILE *fp;
  16.     char buf[256] = {0};
  17.     int r;
  18.  
  19.     if( fh = Open(NAME, MODE_READWRITE) ) {
  20.         Write(fh, MSG, strlen(MSG));
  21.  
  22.         if( fp = fhopen(fh, "r+") ) {
  23.             fseek(fp, 0, SEEK_SET);
  24.             r = fread(buf, 1, 256, fp);
  25.             printf("stdio: <<%s>> len %d\n", buf, r);
  26.             fhclose(fp);
  27.             Seek(fh, 0, OFFSET_BEGINNING);
  28.             r = Read(fh, buf, 256);
  29.             printf("DOS  : <<%s>> len %d\n", buf, r);
  30.         }
  31.         if( fp = fhopen(fh, "w+") ) {
  32.             fseek(fp, 6, SEEK_SET);
  33.             fputs("universe", fp);
  34.             fseek(fp, 0, SEEK_SET);
  35.             r = fread(buf, 1, 256, fp);
  36.             printf("stdio: <<%s>> len %d\n", buf, r);
  37.             fhclose(fp);
  38.             Seek(fh, 0, OFFSET_BEGINNING);
  39.             r = Read(fh, buf, 256);
  40.             printf("DOS  : <<%s>> len %d\n", buf, r);
  41.         }
  42.  
  43.         Seek(fh, 4, OFFSET_BEGINNING);
  44.  
  45.         if( fp = fhopen(fh, "a") ) {
  46.             fputs(" full of wonders", fp);
  47.             fhclose(fp);
  48.         }
  49.  
  50.         if( fp = fhopen(fh, "r+") ) {
  51.             fseek(fp, 0, SEEK_SET);
  52.             r = fread(buf, 1, 256, fp);
  53.             printf("stdio: <<%s>> len %d\n", buf, r);
  54.             fhclose(fp);
  55.             Seek(fh, 0, OFFSET_BEGINNING);
  56.             r = Read(fh, buf, 256);
  57.             printf("DOS  : <<%s>> len %d\n", buf, r);
  58.         }
  59.         Close(fh);
  60.         remove(NAME);
  61.     }
  62.     return 0;
  63. }
  64.  
  65.